Repository navigation
feat: offline app-shell service worker (PWA) - #147
Merged
Merged
Conversation
therealsama
force-pushed
the
feat/pwa-service-worker
branch
2 times, most recently
from
June 27, 2026 17:01
a54f4f1 to
eebe997
Compare
therealsama
force-pushed
the
feat/pwa-service-worker
branch
4 times, most recently
from
June 27, 2026 19:41
a68975a to
62f4c5a
Compare
Add a minimal, dependency-free service worker so an installed PWA cold-boots offline on the very first visit. - public/sw.js: network-first navigation (3s timeout + cached-shell fallback) and cache-first for content-hashed assets, with an install-time precache of the shell plus this build's hashed bundles (parsed from the cached shell HTML) so the app boots offline on the FIRST visit, not just after a warm-up load. Two caches (install-time shell precache + a FIFO-trimmed runtime cache) and skipWaiting + clients.claim for instant takeover. Every cache write is guarded, so a QuotaExceededError under storage pressure can't surface as an unhandled rejection. Cross-origin requests (Algolia / Firebase) are bypassed entirely, so the feed/comments stay live and Playwright's network mocks keep working. The shell is refreshed only from a genuine root navigation, so an unknown deep link served as 404.html (HTTP 200) can't poison the cache; that refresh clones the response synchronously (before it's returned to the page) so it can't silently fail on an already-disturbed body and leave the offline shell pinned to a stale build across deploys. - src/main.tsx: register the SW (production only, on window load; pure progressive enhancement — registration failures are ignored). - src/context/NetworkStatusContext.tsx: detect offline on a cold load even when navigator.onLine wrongly reports online (a SW-served reload, captive portal, or DevTools device-mode "Offline" — no online/offline event fires on a fresh load). When a SW controls the page, verify connectivity with a same-origin, cache-busted HEAD probe that bypasses the SW (it only handles GET) and can't be answered from any HTTP cache, so it genuinely fails offline. A controllerchange listener covers first-install loads where the controller isn't set at mount, and while offline the probe re-runs every 3s so the bar also clears on reconnect (the same stuck navigator.onLine means no online event fires to recover). The poll re-arms even after an inconclusive (timeout) probe, so a transient slow link mid-recovery can't silently end the loop and strand the bar — only a confirmed reachable result stops it. - playwright.config.ts: block service workers by default so existing specs run against the live network; the PWA spec opts back in with test.use(). - e2e/pwa.spec.ts: prove cold-boot offline after a single online visit, and that the offline bar appears on a cold reload when navigator.onLine reports online and then clears on reconnect (online/offline events suppressed so only the probe can move the state).
therealsama
force-pushed
the
feat/pwa-service-worker
branch
from
June 27, 2026 19:58
62f4c5a to
df6e12d
Compare
therealsama
enabled auto-merge
June 27, 2026 20:42
kplachkov
approved these changes
Jun 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a minimal, dependency-free service worker so an installed PWA cold-boots offline on the very first visit.